import {
  createRouter,
  createWebHashHistory
} from 'vue-router'
const Main = () => import('@/views/main/main.vue')
// const movie = () => import('@/views/movie/movie.vue')
// const shop = () => import('@/views/shop/shop.vue')
import movie from '@/views/movie/movie.vue'
import shop from '@/views/shop/shop.vue'
const User = () => import('@/views/user/user.vue')
const Video = () => import('@/views/video/video.vue')
const UserEdit = () => import('@/views/useredit/userEdit.vue')
const AddressManage = () => import('@/views/addressManage/addressManage.vue')
const Cart = () => import('@/views/cart/cart.vue')
const routes = [{
    path: '/',
    name: 'Main',
    component: Main,
    children: [{
        path: '/',
        redirect: '/movie'
      },
      // {path:'',component:Movie,name:'Movie'},
      {
        path: 'movie',
        component: movie,
        name: 'movie',
        meta: {
          noCache: true,
          isRecord: true,
          top: 0
        },
      },
      {
        path: 'user',
        component: User,
        name: 'User',
        meta: {
          isRecord: true,
          top: 0
        }
      },
      {
        path: 'shop',
        component: shop,
        name: 'shop',
        meta: {
          noCache: true,
          isRecord: true,
          top: 0
        },
       
      }
    ],
    beforeEnter: (to, from) => {
     console.log(to)
    },

  },
  {
    path: '/user/edit',
    component: UserEdit,
    name: 'user-edit'
  },
  {
    path: '/user/addressManage',
    component: AddressManage,
    name: 'address-manage'
  },
  {
    path: '/movie/:id',
    component: Video,
    name: 'Video'
  },
  {
    path: '/shop/cart',
    component: Cart,
    name: 'cart'
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
//全局后置钩子
// router.afterEach((to, from) => {
//  console.log(to)
//   //这种办法定位不行vue3
//   if (to.meta.isRecord) {
//     setTimeout(() => {
//       // 则把元信息中的 top 值设为滚动条/*  */纵向滚动的位置
//       window.scrollTo(0, to.meta.top)
//     }, 10)
//   }
// })
export default router